<template>
    <view>
        <view class="tui-actionsheet-class tui-actionsheet" :class="[show ? 'tui-actionsheet-show' : '']" style="bottom: 0;">
            <view class="mb30">
                <view class="titleName">是否设为交易案例：</view>
                <view class="bh-row">
                    <view class="btn" :class="transCaseFlg === 0 ? 'btnActive' : ''" @click="confirmTransCase(0)">
                        否
                    </view>
                    <view class="btn " :class="transCaseFlg === 1 ? 'btnActive' : ''" @click="confirmTransCase(1)">
                        是
                    </view>
                </view>
            </view>
            <view class="mb30">
                <view class="titleName">是否设为优选：</view>
                <view class="bh-row">
                    <view class="btn" :class="initPost.highQuality === 0 ? 'btnActive' : ''" @click="confirmQuality(0)">
                        否
                    </view>
                    <view class="btn " :class="initPost.highQuality === 1 ? 'btnActive' : ''" @click="confirmQuality(1)">
                        是
                    </view>
                </view>
            </view>
            <view class="mb30">
                <view class="titleName">是否设为推荐：</view>
                <view class="bh-row">
                    <view class="btn" :class="initPost.recommend === 0 ? 'btnActive' : ''" @click="confirmRecommend(0)">
                        否
                    </view>
                    <view class="btn " :class="initPost.recommend === 1 ? 'btnActive' : ''" @click="confirmRecommend(1)">
                        是
                    </view>
                </view>
            </view>
            <view class="mb30">
                <view class="titleName">当前审核状态：<text style="color: #F8D247;">{{ postStatusDesc }}</text></view>

            </view>
            <view class="mb30">
                <view class="titleName">请填写拒绝原因：<text class="f24 c9">(非拒绝不必填写)</text> </view>
                <view class="bh-row">
                    <textarea v-model="commentContent" class="comment-text" placeholder="拒绝原因" placeholder-class="textarea-placeholder" autofocus confirm-type="send" />
                </view>
            </view>
            <view class="mb30">
                <view class="titleName">请选择评分：</view>
                <view class="bh-row">
                    <view class=" btn postScore-btn" v-for="(item, index) in postScoreList" :key="index" @click="postScoreChange(item)" :class="postScore == item ? 'postScore-btn-active' : ''">
                        {{ item }}
                    </view>
                </view>
            </view>
            <view class="bh-row bh-justify-space-around bh-align-center">
                <view class="continue" @click="confirmComment(0)">拒绝</view>
                <view class="continue" @click="confirmComment(1)">同意</view>
            </view>
        </view>
        <showCustomModal></showCustomModal>
        <view class="tui-actionsheet-mask" style="top:0" :class="[show ? 'tui-mask-show' : '']" @tap="closeModel"></view>
    </view>
</template>
 
<script>
import { Api } from '../../api/api'
import { BackendApi } from '../../api/backend_api'
import check_utils from './check_utils'
import { CustomDict } from './custom_dict'
import { Dict } from './dict'

export default {
    name: "showAuditSheet",
    emits: ['close', 'confirm',],
    props: {
        //显示操作菜单
        show: {
            type: Boolean,
            default: false
        },
        initValue: {
            type: String,
            default: ''
        },
        initPost: {
            type: Object,
            default: {}
        }
    },
    data() {
        return {
            commentContent: '',
            postScore: '',
            highQuality: 0,
            recommend: 0,
            postScoreList: ['S', 'A', 'B', 'C'],
            transCaseFlg: 0,
        }
    },
    created() {
        this.postScore = this.initPost.postScore
        let that = this
        BackendApi.v05_postTransCase_detail({id: that.initPost.id}).then(res => {
            if(res.code = 200 && res.data){
                that.transCaseFlg = 1
            }
        })
    },
    computed: {
        postStatusDesc() {
            return CustomDict.getDictName(this.initPost.postStatus, Dict.PostStatusEnum)
        }
    },
    mounted() {
    },
    methods: {
        confirmTransCase(toUpdate){
            let that = this
            if (this.transCaseFlg == toUpdate) {
                return
            }
            BackendApi.v05_post_setTransCase({postId: that.initPost.id, value: toUpdate}).then(res => {
                    if(res.code == 200){
                        check_utils.showCustToast('设置成功','success')
                        that.transCaseFlg = toUpdate
                    }else{
                        check_utils.showCustToast(res.msg,'none')
                    }
                })
        },
        postScoreChange(bel) {
            this.postScore = this.postScore == bel ? '' : bel
        },
        focusInput() {
            console.log('自动获得焦点')
            this.firstFocus = true
        },
        closeModel() {
            this.firstFocus = false
            this.$emit('close')
        },
        confirmComment(flg) {
            let that = this
            if (flg == 0) {
                console.log('拒绝', this.commentContent, this.postScore, this.initValue)

                if (check_utils.isEmpty(that.commentContent)) {
                    check_utils.showCustToast('拒绝原因不能为空')
                    return
                }
                Api.PostApi.audit(that, that.initValue, CustomDict.PostStatusEnum.Refuse.value,
                    that.commentContent, '', (callRes) => {
                        if (callRes.code == 200) {
                            that.initPost.postStatus = CustomDict.PostStatusEnum.Refuse.value
                            check_utils.showCustToast('发布已被拒绝')
                            that.$emit('confirm', CustomDict.PostStatusEnum.Refuse.value)
                        } else {
                            check_utils.showCustToast(callRes.msg)
                        }

                    })
            } else if (flg == 1) {
                console.log('同意', this.commentContent, this.postScore, this.initValue)
                if (check_utils.isEmpty(that.postScore)) {
                    check_utils.showCustToast('评分不能为空')
                    return
                }
                Api.PostApi.audit(that, that.initValue, CustomDict.PostStatusEnum.Agree.value,
                    that.commentContent, '', (callRes) => {
                        if (callRes.code == 200) {
                            that.initPost.postStatus = CustomDict.PostStatusEnum.Agree.value
                            check_utils.showCustToast('审核通过了')
                            if(!this.initPost.sourceId){
                                // Api.PostApi.addPostNumber(that, 1)
                            }
                            that.$emit('confirm', CustomDict.PostStatusEnum.Agree.value)
                        } else {
                            check_utils.showCustToast(callRes.msg)
                        }

                    })
            }
        },
        confirmQuality(num) {
            let that = this
            if (this.initPost.highQuality == num) {
                return
            }

            that.showCustomModal({
                content: num == 1 ? '设置为优选？' : '取消优选？',
                title: '',
                cancelText: '取消',
                confirmText: '确定',
                // cancelColor: 'rgba(0, 0, 0, 0.85)',
                // confirmColor: '#666666',
                success(res) {
                    if (res.confirm) {
                        console.log('自定义弹窗点击了确认')
                        Api.PostSellApi.update({ id: that.initValue, highQuality: num }, (res) => {
                            if (res.code == 200) {
                                that.initPost.highQuality = num == 1 ? 1 : 0
                                check_utils.showCustToast('设置成功')
                                that.hideCustomModal()
                            } else {
                                check_utils.showCustToast(res.msg)
                            }
                        })
                    } else {
                        console.log('自定义弹窗点击了取消')
                    }
                }
            })
            // Api.PostSellApi.update({ id: this.initValue, highQuality: this.highQuality }, (res) => {

            // })
        },
        confirmRecommend(num) {
            // this.recommend = num == 1 ? 1 : 0
            // Api.PostSellApi.update({ id: this.initValue, recommend: this.recommend }, (res) => {

            // })
            let that = this
            if (this.initPost.recommend == num) {
                return
            }

            that.showCustomModal({
                content: num == 1 ? '设置为推荐？' : '取消推荐？',
                title: '',
                cancelText: '取消',
                confirmText: '确定',
                // cancelColor: 'rgba(0, 0, 0, 0.85)',
                // confirmColor: '#666666',
                success(res) {
                    if (res.confirm) {
                        console.log('自定义弹窗点击了确认')
                        Api.PostSellApi.update({ id: that.initValue, recommend: num }, (res) => {
                            if (res.code == 200) {
                                that.initPost.recommend = num == 1 ? 1 : 0
                                check_utils.showCustToast('设置成功')
                                that.hideCustomModal()
                            } else {
                                check_utils.showCustToast(res.msg)
                            }
                        })
                    } else {
                        console.log('自定义弹窗点击了取消')
                    }
                }
            })
        }
    }
}
</script>
 
<style scoped lang="scss">
@import url(../../static/css/base.css);

.tui-actionsheet {
    width: 100%;
    position: fixed;
    left: 0;
    right: 0;
    z-index: 9999;
    visibility: hidden;
    transform: translate3d(0, 100%, 0);
    transform-origin: center;
    transition: all 0.3s ease-in-out;
    background: #fff;
    border-top-left-radius: 30rpx;
    border-top-right-radius: 30rpx;
    min-height: 100rpx;
    box-sizing: border-box;
    padding: 60rpx 30rpx;

    .titleName {
        font-weight: 600;
        font-size: 32rpx;
        color: #000;
        margin-bottom: 30rpx;
    }

    .btn {
        width: 110rpx;
        height: 50rpx;
        background-color: #fff;
        border-radius: 8rpx;
        border: 1px solid #000;
        color: #000;
        line-height: 50rpx;
        text-align: center;
        font-size: 24rpx;
        font-weight: 600;
        margin-right: 30rpx;
    }

    .postScore-btn {
        width: 70rpx;
        height: 40rpx;
        line-height: 40rpx;
        margin-right: 20rpx;
    }

    .btnActive,
    .postScore-btn-active {
        background-color: #F8D247;
    }
}

.tui-actionsheet-show {
    transform: translate3d(0, 0, 0);
    visibility: visible;
}

.tui-tips {
    width: 100%;
    padding: 30rpx 60rpx;
    // box-sizing: border-box;
    text-align: center;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tui-operate-box {
    padding-bottom: 12rpx;
}

.tui-actionsheet-btn {
    width: 100%;
    height: 100rpx;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 36rpx;
    position: relative;
}

.tui-btn-last {
    padding-bottom: env(safe-area-inset-bottom);
}

.tui-actionsheet-divider::before {
    content: '';
    width: 100%;
    // border-top: 1rpx solid #d9d9d9;
    position: absolute;
    top: 0;
    left: 0;
    -webkit-transform: scaleY(0.5);
    transform: scaleY(0.5);
}

.tui-actionsheet-cancel {
    color: #1a1a1a;
    padding-bottom: env(safe-area-inset-bottom);
}

.tui-actionsheet-hover {
    background: #f7f7f9;
}

.tui-actionsheet-mask {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    // background: rgba(0, 0, 0, 0.6);
    background: rgba(0, 0, 0, 0.25);
    z-index: 9996;
    transition: all 0.3s ease-in-out;
    opacity: 0;
    visibility: hidden;
}

.tui-mask-show {
    opacity: 1;
    visibility: visible;
}

.textarea-placeholder {
    font-size: 28rpx;
    font-weight: normal;
    color: #999999;
}

.comment-text {
    height: 72rpx;
    background: #F5F6F6;
    border-radius: 10px;
    padding: 10rpx 20rpx;
    font-size: 24rpx;
}

.comment-btn {
    //     width: 70px;
    // height: 40px;
    border-radius: 200rpx;
    opacity: 1;
    padding: 24rpx 38rpx;
    background: #F8D247;

    font-size: 32rpx;
    font-weight: 600;

    color: rgba(0, 0, 0, 0.85);
}

.continue {
    width: 210rpx;
    height: 80rpx;
    background-color: #fff;
    border-radius: 50rpx;
    color: #000;
    line-height: 80rpx;
    text-align: center;
    font-size: 28rpx;
    font-weight: 600;
    background-color: #F8D247;
    margin: 30rpx 0;
}
</style>